package com.gitee.wsl.prism4j.languages

import com.gitee.wsl.prism4j.GrammarUtils
import com.gitee.wsl.prism4j.GrammarUtils.require
import com.gitee.wsl.prism4j.Prism4j
import com.gitee.wsl.prism4j.Prism4j.Companion.pattern
import com.gitee.wsl.prism4j.Prism4j.Companion.token
import com.gitee.wsl.prism4j.annotations.Extend
import com.gitee.wsl.prism4j.Prism4j.Pattern

@Suppress("unused")
@Extend("clike")
object Prism_dart {
    fun create(prism4j: Prism4j): Prism4j.Grammar {
        val dart: Prism4j.Grammar = GrammarUtils.extend(
            require(prism4j, "clike"),
            "dart",
            token(
                "string",
                pattern(Pattern.compile("r?(\"\"\"|''')[\\s\\S]*?\\1"), false, true),
                pattern(Pattern.compile("r?(\"|')(?:\\\\.|(?!\\1)[^\\\\\\r\\n])*\\1"), false, true)
            ),
            token(
                "keyword",
                pattern(Pattern.compile("\\b(?:async|sync|yield)\\*")),
                pattern(Pattern.compile("\\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|default|deferred|do|dynamic|else|enum|export|external|extends|factory|final|finally|for|get|if|implements|import|in|library|new|null|operator|part|rethrow|return|set|static|super|switch|this|throw|try|typedef|var|void|while|with|yield)\\b"))
            ),
            token(
                "operator",
                pattern(Pattern.compile("\\bis!|\\b(?:as|is)\\b|\\+\\+|--|&&|\\|\\||<<=?|>>=?|~(?:\\/=?)?|[+\\-*\\/%&^|=!<>]=?|\\?"))
            )
        )

        GrammarUtils.insertBeforeToken(
            dart, "function",
            token("metadata", pattern(Pattern.compile("@\\w+"), false, false, "symbol"))
        )

        return dart
    }
}
